/**
 * 计算工具类
 * @author hejiacheng
 * @date 2023-7-6
 */

// 注意 weight_diary_wx.showLoading() 和 weight_diary_wx.showToast() 两个最多只能同时存在一个
let computeUtil = {}

//加
computeUtil.add = (num1, num2) => {
	if(num1 == '1024.87'){
		console.log(num1)
	}
	let exp_1 = 0
	let exp_2 = 0
	let nums = 0
	try {
		exp_1 = num1.toString().split('.')[1].length
	} catch {
		exp_1 = 0
	}
	try {
		exp_2 = num2.toString().split('.')[1].length
	} catch {
		exp_2 = 0
	}
	nums = Math.max(exp_1, exp_2);
	// nums 改造成3的倍数
	if(nums % 3 != 0){
		nums = nums + (3 - nums % 3)
	}
	let res = (num1 * Math.pow(10, nums) + num2 * Math.pow(10, nums)) / Math.pow(10, nums)
	return res
}
//减
computeUtil.sub = (num1, num2) => {
	let exp_1 = 0
	let exp_2 = 0
	let nums = 0
	try {
		exp_1 = num1.toString().split('.')[1].length
	} catch {
		exp_1 = 0
	}
	try {
		exp_2 = num2.toString().split('.')[1].length
	} catch {
		exp_2 = 0
	}
	nums = Math.max(exp_1, exp_2);
	// nums 改造成3的倍数
	if(nums % 3 != 0){
		nums = nums + (3 - nums % 3)
	}
	let res = (num1 * Math.pow(10, nums) - num2 * Math.pow(10, nums)) / Math.pow(10, nums)
	return res
}
//乘
computeUtil.mul = (num1, num2) => {
	let exp_1 = 0
	let exp_2 = 0
	let nums = 0
	try {
		exp_1 = num1.toString().split('.')[1].length
		// exp_1 改造成3的倍数
		if(exp_1 % 3 != 0){
			exp_1 = exp_1 + (3 - exp_1 % 3)
		}
	} catch {
		exp_1 = 0
	}
	try {
		exp_2 = num2.toString().split('.')[1].length
		// exp_2 改造成3的倍数
		if(exp_2 % 3 != 0){
			exp_2 = exp_2 + (3 - exp_2 % 3)
		}
	} catch {
		exp_2 = 0
	}
	let res = (num1 * Math.pow(10, exp_1)) * (num2 * Math.pow(10, exp_2)) / Math.pow(10, exp_1 + exp_2)
	return res
}
//除
computeUtil.div = (num1, num2) => {
	let exp_1 = 0
	let exp_2 = 0
	let nums = 0
	try {
		exp_1 = num1.toString().split('.')[1].length
		// exp_1 改造成3的倍数
		if(exp_1 % 3 != 0){
			exp_1 = exp_1 + (3 - exp_1 % 3)
		}
	} catch {
		exp_1 = 0
	}
	try {
		exp_2 = num2.toString().split('.')[1].length
		// exp_2 改造成3的倍数
		if(exp_2 % 3 != 0){
			exp_2 = exp_2 + (3 - exp_2 % 3)
		}
	} catch {
		exp_2 = 0
	}
	let max_exp = Math.max(exp_1, exp_2)
	max_exp = Math.max(max_exp, 3)
	let res = num1 * Math.pow(10, max_exp) / (num2 * Math.pow(10, max_exp))
	return res
	// return (num1 * Math.pow(10, exp_1)) * (num2 * Math.pow(10, exp_2)) / Math.pow(10, exp1 + exp_2)
}




export default computeUtil